using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Sedna.API.Support;
using Spring.Aop;

namespace Sedna.API.Security
{
    public class AuthPointcut: IPointcut 
    {
        private IMethodMatcher methodMatcher = new SessionAwareMethodMatcher();
        
        
        
        
        public IMethodMatcher MethodMatcher
        {
            get { return methodMatcher; }
        }

        public ITypeFilter TypeFilter
        {
            get { return TrueTypeFilter.True; }
        }
        
        
        private class SessionAwareMethodMatcher: IMethodMatcher
        {
            public bool IsRuntime
            {
                get { return false; }
            }

            public bool Matches(System.Reflection.MethodInfo method, Type targetType, object[] args)
            {
                return true;
            }

            public bool Matches(System.Reflection.MethodInfo method, Type targetType)
            {
                ParameterInfo[] parameters = method.GetParameters();
                if (parameters.Length<1) return false;
                if (parameters[0].ParameterType.IsSubclassOf(typeof(IToken)) || parameters[0].ParameterType.Equals(typeof(IToken))) return true;
                return false;
            }

        }
    }
}

